all_data = []
def get_data():
    with open('F:\\qq机器人\\QQChatbotRelease\\QQChatbotRelease\data\\talk_data\\specialQA.txt', 'r', encoding='utf-8') as f:
        for line in f.read().splitlines():
            all_data.append(str(line).split("|"))

get_data()

def add_data(msg):
    if msg[:2] == "rm":
        return [False]

    if msg.count("+") != 1:
        return [False]
    if "/" in msg or "|" in msg:
        return [True, "不能含有/或|呀~"]
    if msg.split("+")[1] == "":
        return [False]
    msg = msg.split("+")
    if len(msg[0]) < 1:
        return [True, "得有内容呀~"]
    for row in all_data:
        if msg[0] == row[0]:
            if msg[1] in row[1]:
                return [True, "这句话我已经会辣，不用再教我啦~"]
            row[1].append(msg[1])
            save_data(all_data)
            return [True, "苏苏酱记住啦~"]
    all_data.append([msg[0], [msg[1]]])
    save_data(all_data)
    return [True, "苏苏酱记住啦~"]


def del_data(del_data):
    if del_data[:2] != "rm":
        return [False]
    msg = del_data[2:].split("+")
    for i in range(len(all_data)):
        if msg[0] == all_data[i][0] and msg[1] == all_data[i][1]:
            print(121212)
            del all_data[i]
            save_data(all_data)
            return [True, "已经删除啦~"]
    return [True, "删除出错啦~"]


def save_data(all_data):
    with open("data/talk_data/specialQA.txt", "w", encoding='UTF-8') as f:
        for row in all_data:
            temp = row[0] + "|" + "".join([i for i in row[1]])
            f.writelines(temp + "\n")
